﻿using System.Collections.Generic;
using UnityEngine;
using Yoozoo.Mars.Got;

namespace WorldMapBase.Tile.Pool
{
    public class ScaleTreePrefabPool : WorldPrefabPool
    {
        public class ScaleTreeParams
        {
            public Transform[] ChildTrees;
            public Vector3[] TreeScale;
        }
        
        public static Dictionary<Transform,ScaleTreeParams> ScaleTreeParamDic = 
            new Dictionary<Transform, ScaleTreeParams>(100);
        
        
        public ScaleTreePrefabPool(int initNum, int capacity, string resPath) :
            base(initNum, capacity, resPath)
        {
            root = WorldPoolManager.TreeRoot;
        }


        protected override Transform ConstructItem()
        {
            Transform objTransform = 
                GameObject.Instantiate(_originObject, GlobalValue.INVISIBLE_POSITION, Quaternion.identity,WorldPoolManager.InstanceRoot).transform;
            
            // 
            ScaleTreeParams pa = new ScaleTreeParams();

            pa.ChildTrees = objTransform.GetComponentsInChildrenWithoutSelf<Transform>();
            if (pa.ChildTrees!=null)
            {
                pa.TreeScale = new Vector3[pa.ChildTrees.Length];
                for (int i = 0; i < pa.ChildTrees.Length; i++)
                {
                    pa.TreeScale[i] = pa.ChildTrees[i].localScale;
                }
            }
            
            ScaleTreeParamDic[objTransform] = pa;
            return objTransform;
        }
    }
}
